package cc.sjfx.sharedoc.widget.adapter;

import java.util.ArrayList;
import java.util.List;

import cc.sjfx.sharedoc.R;
import cc.sjfx.sharedoc.bean.ReplyInfo;
import cc.sjfx.sharedoc.utils.CheckUtils;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ReplyAdapter extends BaseAdapter {
	private List<ReplyInfo> list = new ArrayList<ReplyInfo>();
	private Context context;

	public ReplyAdapter(Context context, List<ReplyInfo> list) {
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		ReplyInfo info = list.get(arg0);
		if (arg1 == null) {
			arg1 = LayoutInflater.from(context).inflate(
					R.layout.listview_reply, null);
			holder = new ViewHolder();
			holder.contentText = (TextView) arg1.findViewById(R.id.replyText);
			holder.nickText = (TextView) arg1.findViewById(R.id.nickText);
			holder.toNickLayout = (LinearLayout) arg1
					.findViewById(R.id.replyToUserLayout);
			holder.toNickText = (TextView) arg1
					.findViewById(R.id.replyToUserText);
			arg1.setTag(holder);
		} else {
			holder = (ViewHolder) arg1.getTag();
		}
		if (CheckUtils.stringIsNull(info.getTo())) {
			holder.toNickLayout.setVisibility(View.GONE);
		} else {
			holder.toNickLayout.setVisibility(View.VISIBLE);
			holder.toNickText.setText(info.getToNick());
		}
		holder.nickText.setText(info.getFromNick());
		holder.contentText.setText(info.getReplyContent());
		return arg1;
	}

	private class ViewHolder {
		TextView contentText;
		TextView nickText;
		TextView toNickText;
		LinearLayout toNickLayout;
	}
}
